package com.megvii.koala.tv.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.megvii.corelib.components.BaseNetworkErrorView;
import com.megvii.koala.base.KoalaPresenter;
import com.megvii.koala.tv.R;
import com.megvii.koala.tv.fragment.param.ServerSettingParam;
import com.megvii.koala.tv.presenter.ServerSettingPresenter;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by linyue on 16/1/22.
 */
public class ServerSettingFragment extends BaseFragment<ServerSettingParam>
{
    protected View rootView;

    @Bind(R.id.server_address)
    protected EditText addressEdit;

    @Bind(R.id.server_confirm)
    protected Button confirmButton;

    private ServerSettingListener listener;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState)
    {
        if (rootView == null)
        {
            rootView = inflater.inflate(R.layout.server_layout, container, false);
        }
        return rootView;
    }

    public String getServerAddress()
    {
        return addressEdit.getText().toString();
    }

    public void setServerAddress(String address)
    {
        addressEdit.setText(address);
    }

    public void setConfirmButtonText(String text)
    {
        confirmButton.setText(text);
    }

    @OnClick(R.id.server_confirm)
    public void onClickConfirm(View view)
    {
        if (listener != null)
        {
            listener.onClickConfirm();
        }
    }

    @Override
    public BaseFragmentListener getBaseFragmentListener()
    {
        return listener;
    }

    @Override
    public Class<? extends KoalaPresenter> getPresenterClass()
    {
        return ServerSettingPresenter.class;
    }

    @Override
    public BaseNetworkErrorView getNetworkErrorView()
    {
        return null;
    }

    public void setListener(ServerSettingListener listener)
    {
        this.listener = listener;
    }

    public interface ServerSettingListener extends BaseFragmentListener
    {
        public void onClickConfirm();
    }
}
